package io.github.hayeka.a1_threadlocalandmultidatasource.code.controller;

//==================================
//      @Author hayeka
//      @Email hayeka@2980.com
//      @Date 2021/6/16
//==================================

import io.github.hayeka.a1_threadlocalandmultidatasource.code.dao.UserDAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/users")
public class UserController {

    private static final Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserDAO userDAO;

    @GetMapping("/msg")
    public Object msg() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("msg", "OK");
        return map;
    }

    @GetMapping("")
    public Object users() {
        logger.info("控制器:[{}],DAO:[{}]",getClass().getName(),userDAO);
        HashMap<String, Object> map = new HashMap<>();
        map.put("msg", "OK");
        map.put("data",userDAO.findAll());
        return map;
    }

}
